package com.runvp.rest.biz;

import java.util.List;

import com.runvp.common.annotation.ParamValid;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.runvp.common.annotation.Log;
import com.runvp.common.enums.BusinessType;
import com.runvp.service.biz.domain.BizRechargePackage;
import com.runvp.service.biz.service.IBizRechargePackageService;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.utils.poi.ExcelUtil;
import com.runvp.common.core.page.TableDataInfo;

/**
 * 充值套餐Controller
 * 
 * @author runvp
 * @date 2022-09-18
 */
@Controller
@RequestMapping("/biz/rechargePackage")
public class BizRechargePackageController extends BaseController {
    private String prefix = "biz/rechargePackage";

    @Autowired
    private IBizRechargePackageService bizRechargePackageService;

    @RequiresPermissions("biz:rechargePackage:view")
    @GetMapping()
    public String rechargePackage()
    {
        return prefix + "/rechargePackage";
    }

    /**
     * 查询充值套餐列表
     */
    @RequiresPermissions("biz:rechargePackage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizRechargePackage bizRechargePackage) {
        startPage();
        List<BizRechargePackage> list = bizRechargePackageService.selectBizRechargePackageList(bizRechargePackage);
        return getDataTable(list);
    }

    /**
     * 导出充值套餐列表
     */
    @RequiresPermissions("biz:rechargePackage:export")
    @Log(title = "充值套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizRechargePackage bizRechargePackage) {
        List<BizRechargePackage> list = bizRechargePackageService.selectBizRechargePackageList(bizRechargePackage);
        ExcelUtil<BizRechargePackage> util = new ExcelUtil<BizRechargePackage>(BizRechargePackage.class);
        return util.exportExcel(list, "充值套餐数据");
    }

    /**
     * 新增充值套餐
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存充值套餐
     */
    @ParamValid
    @RequiresPermissions("biz:rechargePackage:add")
    @Log(title = "充值套餐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizRechargePackage bizRechargePackage) {
        return toAjax(bizRechargePackageService.insertBizRechargePackage(bizRechargePackage));
    }

    /**
     * 修改充值套餐
     */
    @RequiresPermissions("biz:rechargePackage:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizRechargePackage bizRechargePackage = bizRechargePackageService.selectBizRechargePackageById(id);
        mmap.put("bizRechargePackage", bizRechargePackage);
        return prefix + "/edit";
    }

    /**
     * 修改保存充值套餐
     */
    @ParamValid
    @RequiresPermissions("biz:rechargePackage:edit")
    @Log(title = "充值套餐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizRechargePackage bizRechargePackage) {
        return toAjax(bizRechargePackageService.updateBizRechargePackage(bizRechargePackage));
    }

    /**
     * 删除充值套餐
     */
    @RequiresPermissions("biz:rechargePackage:remove")
    @Log(title = "充值套餐", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizRechargePackageService.deleteBizRechargePackageByIds(ids));
    }
}
